package com.example.sppmode.Common;

import android.content.SharedPreferences;

import com.example.sppmode.DataAccess.MyData;


public class AppInfo {
    public static final String KEY_FIRST_RUNNING    = "key.FIRST_RUNNING";

    private String name;
    private String version;
    private boolean firstRunning = false;

    public AppInfo(){

    }

    public void initData(){
        firstRunning = readFirstRunningFromSp();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public boolean isFirstRunning() {
        return firstRunning;
    }

    public void setFirstRunning(boolean firstRunning) {
        this.firstRunning = firstRunning;
        updateFirstRunningToSp(firstRunning);
    }

    private boolean updateFirstRunningToSp(boolean firstRunning) {
        SharedPreferences sp = MyData.getInstance().getMySP();

        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(KEY_FIRST_RUNNING, firstRunning);
        editor.commit();
        return true;
    }

    private boolean readFirstRunningFromSp() {
        SharedPreferences sp = MyData.getInstance().getMySP();
        return sp.getBoolean(KEY_FIRST_RUNNING, true);
    }
}
